package com.weic.manager.ask.controller;

import com.weic.manager.ask.service.AskService;
import com.weic.manager.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * 问答
 */
@Controller
@RequestMapping(value = "/ask")
public class AskController extends BaseController {

    @Autowired
    AskService askService;

    /**
     * 问答列表
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/ask_list.html")
    public ModelAndView articleList(HttpServletRequest request , HttpServletResponse response){

        return new ModelAndView("/ask_list.html");
    }

    /**
     * 问答页面
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/ask.html")
    public ModelAndView ask(HttpServletRequest request , HttpServletResponse response){

        return new ModelAndView("/ask.html");
    }

    /**
     * 获取答案
     * @param request
     * @return
     */
    @RequestMapping(value = "/askQuestion.json")
    public @ResponseBody Map<String,Object> askForAnser(HttpServletRequest request){
        String question = request.getParameter("question");
        return genAjaxResponse(true,"请求成功！",askService.getAnser(question));
    }
}
